const fs = require('fs');
const parser = require("@babel/parser");
const traverse = require("@babel/traverse").default;
const tee = require("@babel/types");
const generator = require("@babel/generator").default;
const template = require("@babel/template").default;

let yuanwj = fs.readFileSync('./al.js', {encoding: "utf-8"});
let ast = parser.parse(yuanwj);


let jiexswitch = {

}

let shuz = {};
let gxcc = {};
let hansyx = [];


let parserData = {
    CallExpression(path){
        if (path.node.callee.name === "Cbb"){
            
            let sei = path.parentPath.container[1];
            for (let i = 0; i < sei.cases.length; i++){
                shuz[sei.cases[i].test.value] = sei.cases[i].consequent;
                let obj = sei.cases[i].consequent;

                if (obj[obj.length - 2].type === "ReturnStatement") {
                    continue
                }
     

                let lt = obj[obj.length - 2].expression.right

                if (lt.type === "ConditionalExpression") {
                    let ggg = tee.callExpression(tee.identifier('cbbll'),[lt.test, sei.cases[i].test])
                    obj.splice(obj.length - 2,0,ggg);
                }
            }
        }
    }

}



traverse(ast,parserData)
let gg = generator(ast).code
fs.writeFileSync('./newal.js',gg+'')


